﻿<!DOCTYPE html>
<html>
<head>
    <title data-i18n="commands-title">ASF | Commands</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script> <!--Change to cdnjs once available-->
    <link rel="icon" href="../img/favicon.png" type="image/png">
    <link rel="shortcut icon" href="../img/favicon.ico" type="img/x-icon">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-sweetalert/1.0.1/sweetalert.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/admin-lte/2.4.3/css/AdminLTE.min.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
    <link rel="stylesheet" href="../css/_all-skins.min.css">
    <link rel="stylesheet" href="../css/app.css">
    <link rel="stylesheet" href="../css/_nightmode.min.css">
</head>
<body class="hold-transition skin-blue sidebar-mini fixed">
    <div class="wrapper">
        <!-- Header -->
        <header class="main-header">
            <!-- Logo -->
            <a href="javascript:void(0)" class="logo">
                <span class="logo-mini"><b>A</b>SF</span>
                <span class="logo-lg"><b>Archi</b>SteamFarm</span>
            </a>

            <nav class="navbar navbar-static-top" role="navigation">
                <!-- Left Sidebar Toggle Button-->
                <a href="javascript:void(0)" class="sidebar-toggle" id="leftSidebar" data-toggle="push-menu" role="button">
                    <i class="fas fa-bars"></i>
                    <span class="sr-only" data-i18n="global-navigation">Toggle navigation</span>
                </a>
                <div class="navbar-custom-menu">
                    <ul class="nav navbar-nav">
                        <!-- Right Sidebar Toggle Button -->
                        <li><a href="javascript:void(0)" data-toggle="control-sidebar"><i class="fas fa-cogs"></i></a></li>
                    </ul>
                </div>
            </nav>
        </header>

        <!-- Left Sidebar -->
        <aside class="main-sidebar">
            <section class="sidebar">
                <ul class="sidebar-menu" data-widget="tree">
                    <li class="header" data-i18n="global-home">Home</li>
                    <li class="active"><a href="commands.html"><i class="fas fa-laptop fa-fw"></i> <span data-i18n="global-commands">Commands</span></a></li>
                    <li>
                        <a href="bots.html">
                            <i class="fas fa-users fa-fw"></i> <span data-i18n="global-bots">Bots</span>
                            <span class="pull-right-container bot-status">
                                <small class="label pull-right bg-gray" id="offlineBots">0</small>
                                <small class="label pull-right bg-yellow" id="onlineBots">0</small>
                                <small class="label pull-right bg-olive" id="farmingBots">0</small>
                            </span>
                        </a>
                    </li>
                    <li><a href="log.html"><i class="far fa-file-alt fa-fw"></i> <span data-i18n="global-log">Log</span></a></li>

                    <li class="header" data-i18n="global-config">Config</li>
                    <li><a href="editor.html"><i class="far fa-edit fa-fw"></i> <span data-i18n="global-editor">Editor</span></a></li>
                    <li><a href="generator.html"><i class="far fa-copy fa-fw"></i> <span data-i18n="global-generator">Generator</span></a></li>

                    <li class="header" data-i18n="global-information">Information</li>
                    <li class="info-overview">
                        <a>
                            <i class="fas fa-tachometer-alt fa-fw"></i> <span data-i18n="global-ram-usage">RAM Usage</span>
                            <span class="pull-right-container">
                                <small class="label pull-right bg-blue" id="ramUsage">0.00 MB</small>
                            </span>
                        </a>
                    </li>
                    <li class="info-overview">
                        <a>
                            <i class="far fa-clock fa-fw"></i> <span data-i18n="global-uptime">Uptime</span>
                            <span class="pull-right-container">
                                <small class="label pull-right bg-blue" id="uptime">0d 0h 0m</small>
                            </span>
                        </a>
                    </li>
                </ul>
            </section>
        </aside>

        <!-- Content -->
        <div class="content-wrapper">
            <section class="content-header">
                <h1>
                    <span data-i18n="global-commands">Commands</span>
                    <small data-i18n="global-control-panel">Control Panel</small>
                </h1>
                <ol class="breadcrumb">
                    <li><i class="fas fa-home"></i> <span data-i18n="global-home">Home</span></li>
                    <li class="active"><i class="fas fa-laptop"></i> <span data-i18n="global-commands">Commands</span></li>
                </ol>
            </section>

            <!-- Content Body -->
            <section class="content container-fluid">
                <div class="box">
                    <div class="box-header with-border">
                        <i class="fas fa-laptop"></i>
                        <h3 class="box-title" data-i18n="global-commands">Commands</h3>
                        <div class="box-tools pull-right">
                            <div class="btn-group">
                                <button type="button" class="btn btn-box-tool dropdown-toggle" data-toggle="dropdown">
                                    <i class="fas fa-wrench"></i>
                                </button>
                                <ul class="dropdown-menu" role="menu">
                                    <li><button data-i18n="title-commands-auto-clear" title="Toggle auto clear" type="button" class="btn btn-box-tool text-olive" id="chkAutoClear"><i id="iconAutoClear" class="fas fa-toggle-on fa-2x"></i></button><span data-i18n="commands-auto-clear">Auto clear</span></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="box-body">
                        <div class="box-content-commands"></div>
                        <input type="text" class="form-control" id="commandSent" disabled>
                    </div>
                    <div class="box-footer">
                        <div class="input-group">
                            <div class="input-group-btn hidden-xs" id="cmdsDropDownBox">
                                <button data-i18n="title-commands-show-all-commands" title="Show all commands" type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <span data-i18n="global-commands">Commands</span>
                                    <span class="fas fa-caret-down" id="iconCmdsDropDownBox"></span>
                                </button>
                                <ul class="dropdown-menu scrollable-menu" id="commandsDropDown"></ul>
                            </div>
                            <div class="input-group-btn hidden-xs" id="botsDropDownBox">
                                <button data-i18n="title-commands-show-all-bots" title="Show all bots" type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <span data-i18n="global-bots">Bots</span>
                                    <span class="fas fa-caret-down" id="iconBotsDropDownBox"></span>
                                </button>
                                <ul class="dropdown-menu scrollable-menu" id="botsDropDown"></ul>
                            </div>
                            <input id="commandInput" type="text" class="form-control" data-i18n="placeholder-commands" placeholder="Type command...">
                            <div class="input-group-btn">
                                <button data-i18n="title-commands-send" title="Send command" type="button" class="btn btn-default" id="sendCommand"><i class="far fa-paper-plane"></i></button>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
        </div>

        <!-- Footer -->
        <footer class="main-footer">
            <div class="pull-right"><strong data-i18n="global-version">Version</strong> <span id="version">0.0.0.0</span></div>
            <strong>
                <a target="_blank" href="https://github.com/JustArchi/ArchiSteamFarm">GitHub</a> -
                <a target="_blank" href="https://github.com/JustArchi/ArchiSteamFarm/wiki"><span data-i18n="global-wiki">Wiki</span></a> -
                <a target="_blank" href="https://github.com/JustArchi/ArchiSteamFarm/commits/master" id="changelog"><span data-i18n="global-changelog">Changelog</span></a>
            </strong>
        </footer>

        <!-- Right Sidebar -->
        <aside class="control-sidebar control-sidebar-dark">
            <div class="tab-content">
                <div class="tab-pane" id="control-right-sidebar"></div>
            </div>
        </aside>

        <div class="control-sidebar-bg"></div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/interact.js/1.2.9/interact.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-sweetalert/1.0.1/sweetalert.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/admin-lte/2.4.3/js/adminlte.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.i18n/1.0.4/jquery.i18n.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.i18n/1.0.4/jquery.i18n.messagestore.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.i18n/1.0.4/jquery.i18n.fallbacks.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.i18n/1.0.4/jquery.i18n.language.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.i18n/1.0.4/jquery.i18n.parser.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.i18n/1.0.4/jquery.i18n.emitter.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.i18n/1.0.4/jquery.i18n.emitter.bidi.min.js"></script>
    <script src="../js/utils.js"></script>
    <script src="../js/i18n.js"></script>
    <script src="../js/app.js"></script>
    <script>
        $(function () {
            'use strict';

            store('CurrentPage', 'pages/commands.html');

            var $chkAutoClear = $('#chkAutoClear'),
                $commandInput = $('#commandInput'),
                $cmdsDropDownBox = $('#cmdsDropDownBox'),
                $botsDropDownBox = $('#botsDropDownBox'),
                $botsDropDown = $("#botsDropDown"),
                $commandsDropDown = $("#commandsDropDown");
            
            var myCommands = { // For the future: Make this dynamic
                'addlicense': 'Activates given appIDs (Steam Network) or subIDs (Steam Store) on given bot instances (free games only).',
                'redeem': 'Redeems given cd-keys on given bot instances.',
                '2faok': 'Accepts all pending 2FA confirmations for given bot instances.',
                '2fa': 'Generates temporary 2FA token for given bot instances.',
                'loot': 'Sends all MatchableTypes items of given bot instances to Master user defined in their SteamUserPermissions (with lowest steamID if more than one).',
                'play': 'Switches to manual farming - launches given AppIDs on given bot instances, optionally also with custom GameName. Use !resume for returning to automatic farming.',
                'start': 'Starts given bot instances.',
                'stop': 'Stops given bot instances.',
                'pause': 'Permanently pauses automatic cards farming module of given bot instances. ASF will not attempt to farm current account in this session, unless you manually !resume it, or restart the process. Also called sticky pause.',
                'resume': 'Resumes automatic farming of given bot instances. Also see !pause, !play.',
                'restart': 'Restarts ASF process.'
            };

            var keyCount = 0,
                prevCommand = (JSON.parse(get('prevCommand')) === null) ? [] : JSON.parse(get('prevCommand'));

            $commandInput.focus();

            $('#sendCommand').click(function (e) {
                var cmd = $commandInput.val();
                keyCount = 0;

                if (typeof prevCommand[prevCommand.length - 1] === 'undefined') {
                    prevCommand.push(cmd);
                } else if (prevCommand[prevCommand.length - 1] !== cmd) {
                    prevCommand.push(cmd);
                }

                store('prevCommand', JSON.stringify(prevCommand.slice(-20))); // Only save the last 20 commands
                prevCommand = (JSON.parse(get('prevCommand')) === null) ? [] : JSON.parse(get('prevCommand'));

                sendCommand();
                e.preventDefault();
            });

            //#region Merge to one function
            $(document).keydown(function (e) {
                if (e.which == 38 && $commandInput.is(':focus')) {
                    if (prevCommand.length > keyCount) keyCount++;
                    var index = prevCommand.length - keyCount;
                    $commandInput.val(prevCommand[index]);
                } else if (e.which == 40 && $commandInput.is(':focus')) {
                    if (keyCount > 0) keyCount--;
                    var index = prevCommand.length - keyCount;
                    $commandInput.val(prevCommand[index]);
                }
            });

            $(document).keypress(function (e) {
                var keyCode = e.keyCode || e.which;

                if (keyCode == 13 && $cmdInput.val() !== "") {
                    e.preventDefault();
                    $('#sendCommand').click();
                }
            });
            //#endregion Merge to one function
            
            $('.box-tools').ready(function () {
                var tmpAutoClear = get('autoClear');

                if (tmpAutoClear === 'false') {
                    $chkAutoClear.removeClass('text-olive');
                    $chkAutoClear.addClass('text-grey');
                    $('#iconAutoClear').addClass('fa-rotate-180');
                }
            });

            $chkAutoClear.click(function () {
                if ($('#iconAutoClear').hasClass('fa-rotate-180')) {
                    $('#iconAutoClear').removeClass('fa-rotate-180');
                    $chkAutoClear.removeClass('text-grey');
                    $chkAutoClear.addClass('text-olive');
                    $chkAutoClear.blur();
                    store('autoClear', true);
                } else {
                    $('#iconAutoClear').addClass('fa-rotate-180');
                    $chkAutoClear.removeClass('text-olive');
                    $chkAutoClear.addClass('text-grey');
                    $chkAutoClear.blur();
                    store('autoClear', false);
                }
                return false;
            });
            
            $('.box-content-commands').ready(function () {
                var tmpCommandHeight = get('commandHeight');

                if (tmpCommandHeight) {
                    $('.box-content-commands').css('height', tmpCommandHeight + 'px');

                    if (tmpCommandHeight > 475) {
                        $cmdsDropDownBox.addClass('dropup');
                        $botsDropDownBox.addClass('dropup');
                        $('#iconCmdsDropDownBox').removeClass('fa-caret-down');
                        $('#iconCmdsDropDownBox').addClass('fa-caret-up');
                        $('#iconBotsDropDownBox').removeClass('fa-caret-down');
                        $('#iconBotsDropDownBox').addClass('fa-caret-up');
                    } else {
                        $cmdsDropDownBox.removeClass('dropup');
                        $botsDropDownBox.removeClass('dropup');
                        $('#iconCmdsDropDownBox').removeClass('fa-caret-up');
                        $('#iconCmdsDropDownBox').addClass('fa-caret-down');
                        $('#iconBotsDropDownBox').removeClass('fa-caret-up');
                        $('#iconBotsDropDownBox').addClass('fa-caret-down');
                    }
                } else {
                    $('.box-content-commands').css('height', 400 + 'px');
                }
            });

            interact('.box-content-commands')
                .resizable({
                    edges: { left: false, right: false, bottom: true, top: false },
                    restrictEdges: {
                        outer: 'parent',
                        endOnly: true,
                    },
                    inertia: true,
                })
                .on('resizemove', function (event) {
                    var target = event.target;
                    target.style.height = event.rect.height + 'px';
                })
                .on('resizeend', function (event) {
                    var currentHeight = parseInt(event.target.style.height, 10);
                    store('commandHeight', currentHeight);

                    if (currentHeight > 475) {
                        $cmdsDropDownBox.addClass('dropup');
                        $botsDropDownBox.addClass('dropup');
                        $('#iconCmdsDropDownBox').removeClass('fa-caret-down');
                        $('#iconCmdsDropDownBox').addClass('fa-caret-up');
                        $('#iconBotsDropDownBox').removeClass('fa-caret-down');
                        $('#iconBotsDropDownBox').addClass('fa-caret-up');
                    } else {
                        $cmdsDropDownBox.removeClass('dropup');
                        $botsDropDownBox.removeClass('dropup');
                        $('#iconCmdsDropDownBox').removeClass('fa-caret-up');
                        $('#iconCmdsDropDownBox').addClass('fa-caret-down');
                        $('#iconBotsDropDownBox').removeClass('fa-caret-up');
                        $('#iconBotsDropDownBox').addClass('fa-caret-down');
                    }
                });

            $('.box-footer').ready(function () {
                for (var cmd in myCommands) { // Fill drop down with all commands
                    if (myCommands.hasOwnProperty(cmd)) {
                        $commandsDropDown.append('<li><a href="javascript:void(0)" id="' + cmd + '" onclick="fillCommand(\'' + cmd + '\')">' + cmd + '</a></li>');

                        $('#' + cmd)
                            .mouseenter(function () {
                                $commandInput.attr('placeholder', myCommands[this.id]); // ToDo: Find a better solution for where to display description
                            })
                            .mouseleave(function () {
                                $commandInput.attr('placeholder', $.i18n('placeholder-commands'));
                            });
                    }
                }

                $botsDropDown.append('<li><a href="javascript:void(0)" onclick="fillBots(\'ASF\')">ASF</a></li>'); // Fill with default value

                $.ajax({ // Fill drop down with all bots + ASF
                    url: '/Api/Bot/ASF',
                    type: 'GET',
                    success: function (data) {
                        var json = data['Result'];

                        $botsDropDown.append('<li class="divider"></li>');

                        for (var i = 0; i < json.length; i++) {
                            var obj = json[i],
                                botName = obj.BotName;

                            $botsDropDown.append('<li><a href="javascript:void(0)" onclick="fillBots(\'' + botName + '\')">' + botName + '</a></li>');
                        }
                    }
                });
            });
        })
    </script>
</body>
</html>
